<template>
  <div class="mod-sys__qarrawdatainfo">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input v-model="state.dataForm.filename" placeholder="qar文件名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.aircraftid" placeholder="机号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="state.exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="filename" width="188" label="文件名称" header-align="center" align="center"></el-table-column>
      <el-table-column prop="convertstate" label="是否转码" header-align="center" align="center">
        <template v-slot="scope">
          {{ state.getDictLabel("QAR_CONVERTSTATE", scope.row.convertstate) }}
        </template>
      </el-table-column>
      <el-table-column prop="qardate" width="140" label="显示日期" header-align="center" align="center"></el-table-column>
      <el-table-column prop="postdate" width="140" label="传输日期" header-align="center" align="center"></el-table-column>
      <el-table-column prop="aircraftid" label="机号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="filepath" width="288" label="文件路径" header-align="center" align="center"></el-table-column>
      <!-- <el-table-column prop="timestamps" label="入库时间戳" header-align="center" align="center"></el-table-column> -->
      <el-table-column prop="rawstate" width="100" label="文件状态" header-align="center" align="center">
        <template v-slot="scope">
          {{ state.getDictLabel("qar_rawstate", scope.row.rawstate) }}
        </template>
      </el-table-column>
      <el-table-column prop="flightsnum" label="包含航班数" header-align="center" align="center"></el-table-column>
      <el-table-column prop="qarsize" width="100" label="源文件大小" header-align="center" align="center"></el-table-column>
      <el-table-column prop="hdfssize" label="压缩文件大小" header-align="center" align="center"></el-table-column>
      <el-table-column prop="isvalid" label="有效标识" header-align="center" align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('sys:qarrawdatainfo:info')" type="primary" link @click="browseHandle(scope.row)">查看译码文件</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <RawDataInfo :key="addKey" ref="addOrUpdateRef" @refreshDataList="state.getDataList"></RawDataInfo>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { nextTick, reactive, ref, toRefs, watch } from "vue";
import RawDataInfo, {IParams} from "./rawdatainfo.vue";
const view = reactive({
  getDataListURL: "/sys/qarrawdatainfo/page",
  getDataListIsPage: true,
  exportURL: "/sys/qarrawdatainfo/export",
  deleteURL: "/sys/qarrawdatainfo",
  deleteIsBatch: true,
  dataForm: {
    filename: "",
    aircraftid: "",
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });


const addKey = ref(0);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (params: IParams) => {
  addKey.value++;
  nextTick(() => {
    addOrUpdateRef.value.init(params);
  });
};
const browseHandle = (record:any) => {
  addOrUpdateHandle({
    filename: record.filename, 
    qarType: "B737_7",
    columns: "DATETIME,aAILL,28SBS2,28VB1S2,28HBB"
  });
}
</script>